package com.Data;

import java.io.BufferedOutputStream;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.ObjectInput;
import java.io.ObjectInputStream;
import java.io.ObjectOutputStream;
import java.io.Serializable;
import java.io.StreamCorruptedException;

public class Configuration implements Serializable, Storable {
	private static final long serialVersionUID = -2691088310295105431L;
	
	private float vol;
	private float video;

	public Configuration() {
		this.vol = 0.5f;
		this.video = 0.4f;
	}
	
	public Configuration(float vol, float video) {
		this.vol = vol;
		this.video = video;
	}

	@Override
	public void setData(Storable data) {
		Configuration object = (Configuration)data;
		this.vol = object.vol;
		this.video = object.video;
	}
	
	public boolean save() {
		try {
			File f = new File(FileManager.getMainPath()+"/conf");
			FileOutputStream fos;
				fos = new FileOutputStream(f);
			ObjectOutputStream oos = new ObjectOutputStream(new BufferedOutputStream(fos));
			oos.writeObject(this);
			oos.close();
			
			return true;
		} catch (FileNotFoundException e) {
			e.printStackTrace();
		} catch (IOException e) {
			e.printStackTrace();
		}
		return false;
	}
	
	public boolean load() {
		try {
			File f = new File(FileManager.getMainPath()+"/conf");
			FileInputStream fis = new FileInputStream(f);
			ObjectInput ois = new ObjectInputStream(fis);
			Storable data = (Storable)ois.readObject();
			
			setData(data);
			
			return true;
		} catch (FileNotFoundException e) {
			e.printStackTrace();
		} catch (StreamCorruptedException e) {
			e.printStackTrace();
		} catch (IOException e) {
			e.printStackTrace();
		} catch (ClassNotFoundException e) {
			e.printStackTrace();
		}
		return false;
	}

	public float getVol() {	return vol;	}
	public void setVol(float vol) {	this.vol = vol;	}
	public float getVideo() {	return video;	}
	public void setVideo(float video) {	this.video = video;	}
	
}
